package cn.com.simple.learning.designpattern.behavior.mediator;

/**
 * @author Jianxing.Jia
 * @date 2022/2/9
 * @description 描述信息
 */
public class Broker {

    private Alarm alarm;
    private Coffee coffee;

    public void setAlarm(Alarm alarm) {
        this.alarm = alarm;
    }

    public void setCoffee(Coffee coffee) {
        this.coffee = coffee;
    }

    public void onEvent(EventType eventType, boolean checkSth) {
        switch (eventType) {
            case ALARM:
                System.out.println("闹钟响了，检查其他服务是否需要触发执行...");
                if (checkSth) {
                    coffee.make();
                } else {
                    System.out.println("暂无需要处理的事件...");
                }
                break;

            case WEEKEND:
                System.out.println("周末了，不需要闹钟...");
                alarm.close();
                break;

            case TRASH_DAY:
                System.out.println("垃圾清理日，闹钟需要提前报时...");
                alarm.setTime(-15);
                break;

            default:
                throw new IllegalArgumentException("unsupported eventType ...");
        }
    }


}
